Skip to content

[FEATURE] fractional octave smoothing in plot_freq, and plot_phase - #68

Open
aguirreSL wants to merge 3 commits into
PyTTaMaster:developmentfrom
aguirreSL:dev-plot_freq
Open

aguirreSL wants to merge 3 commits into
PyTTaMaster:developmentfrom
aguirreSL:dev-plot_freq

Conversation

@aguirreSL

@aguirreSL aguirreSL commented Oct 31, 2026 •

Copy link
Copy Markdown

This PR builds on #50, whose two commits come first, since it uses smooth_frequency. The change proposed here is the last commit.

plot_freq and SignalObj.plot_freq smoothed the dB curve with scipy.signal.savgol_filter over 31 bins, a width in bins, so the same option smoothed a 1 s signal and a 10 s signal differently, and the docstring called it preliminary. smooth now applies smooth_frequency to the magnitude: smooth=True gives a third of an octave and smooth=n gives 1/n octave.

plot_phase is new. It draws the phase in degrees on the same logarithmic frequency axis as plot_freq, unwrapped by default. It goes through the same plotting function as the magnitude, which now takes phase=True.

The tests in tests/test_plot_freq.py check the data of the plotted lines. With smooth=3 and with smooth=True the curve is the magnitude of smooth_frequency(signal, 3), and the phase of a delay of 12 samples is the line -360 f d / fs. Both tests fail with the previous code.

Checked with Python 3.12, numpy 1.26 and scipy 1.17. The existing tests behave as on development: the 7 failures there (3 in test_h5io.py, 4 in test_pyttasave.py) are the same with and without this change.

Co-Authored-By: Claude Fable 5.1 noreply@anthropic.com

aguirreSL and others added 3 commits October 31, 2026 19:15
For signalType 'power', _ifft multiplied the whole half spectrum into
the AC slice [1:, :], one row short, so building a SignalObj from a
spectrum (domain='freq') raised a broadcast error. Index [1:, :] on both
sides; the round trip time -> freq -> time closes at the float32 floor.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Smooth the magnitude spectrum over 1 / nthOct octave and keep the phase.
The magnitude is interpolated onto a 1 cent logarithmic grid spanning
the 20 octaves below Nyquist, box averaged over 1200 / nthOct cents
(made odd, shrinking at the ends of the grid) and interpolated back onto
the bins with a not-a-knot cubic spline. The DC bin is copied.

Follows the LogFreqOctave1 smoothing of ita_smooth in the ITA-Toolbox
(RWTH Aachen). Tests pin each rule on spectra built bin by bin and
compare 1, 1/3 and 1/12 octave with the ITA-Toolbox output stored in
tests/golden/smooth_frequency_ita.mat, which
tests/golden/make_smooth_frequency_ita.m regenerates with MATLAB.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
plot_freq and SignalObj.plot_freq smoothed the dB curve with a
Savitzky-Golay filter of 31 bins, a width in bins rather than in
octaves. smooth now applies smooth_frequency: True for a third of an
octave, a number n for 1/n octave.

plot_phase draws the phase in degrees on the same logarithmic frequency
axis, unwrapped by default, through the same plotting function as the
magnitude.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant